package net.shopxx.entity;

import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.compass.annotations.SearchableProperty;
import org.compass.annotations.Store;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.OrderBy;

/**
 * 实体类 - 颜色
 */

@Entity
@Table(name = "product_item")
public class Productitem extends BaseEntity {

	private static final long serialVersionUID = -6109590619136943215L;

	private Product product;// 名称
	
	private String itemSn;
	
	private Integer store;// 商品库存数量
	
	private Integer freezeStore;// 被占用库存数

	private BigDecimal price;// 商品价格

	private Color color;// 颜色
	
	private PropertiesValue propertiesValue;

//	private Member member;

	private List<CartItem> cartItem;
	private List<OrderItem> orderItem;
	private Set<CartItemProduct> cartItemSet;// 购物车项
	private Set<OrderItem> orderItemSet;// 订单项
	private Set<DeliveryItem> deliveryItemSet;// 物流项
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(nullable = false)
	public Product getProduct() {
		return product;
	}
	
	public void setProduct(Product product) {
		this.product = product;
	}

//	@ManyToOne(fetch = FetchType.LAZY)
//	@Cascade(value = { CascadeType.DELETE })
//	@OrderBy(clause = "modifyDate desc")
//	public ProductColor getProductColor() {
//		return productColor;
//	}
//
//	public void setProductColor(ProductColor productColor) {
//		this.productColor = productColor;
//	}

	@ManyToOne(fetch = FetchType.LAZY)
	@Cascade(value = { CascadeType.PERSIST })
	@OrderBy(clause = "modifyDate desc")
	public PropertiesValue getPropertiesValue() {
		return propertiesValue;
	}

	public void setPropertiesValue(PropertiesValue propertiesValue) {
		this.propertiesValue = propertiesValue;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@Cascade(value = { CascadeType.PERSIST })
	@OrderBy(clause = "modifyDate desc")
	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	@OneToMany(fetch = FetchType.LAZY)
	@Cascade(value=CascadeType.DELETE)
	public List<CartItem> getCartItem() {
		return cartItem;
	}

	public void setCartItem(List<CartItem> cartItem) {
		this.cartItem = cartItem;
	}

	@OneToMany(fetch = FetchType.LAZY)
	public List<OrderItem> getOrderItem() {
		return orderItem;
	}

	public void setOrderItem(List<OrderItem> orderItem) {
		this.orderItem = orderItem;
	}
	
	@SearchableProperty(store = Store.YES)
	public Integer getStore() {
		return store;
	}

	public void setStore(Integer store) {
		this.store = store;
	}
	
	@SearchableProperty(store = Store.YES)
	@Column(nullable = false)
	public Integer getFreezeStore() {
		return freezeStore;
	}

	public void setFreezeStore(Integer freezeStore) {
		this.freezeStore = freezeStore;
	}
	
	@OneToMany(fetch = FetchType.LAZY)
	@Cascade(value = { CascadeType.DELETE })
	public Set<CartItemProduct> getCartItemSet() {
		return cartItemSet;
	}

	public void setCartItemSet(Set<CartItemProduct> cartItemSet) {
		this.cartItemSet = cartItemSet;
	}
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "productitem")
	@Cascade(value = { CascadeType.DELETE})
	public Set<OrderItem> getOrderItemSet() {
		return orderItemSet;
	}

	public void setOrderItemSet(Set<OrderItem> orderItemSet) {
		this.orderItemSet = orderItemSet;
	}

	@OneToMany(mappedBy = "productitem", fetch = FetchType.LAZY)
	@Cascade(value = { CascadeType.DELETE})
	public Set<DeliveryItem> getDeliveryItemSet() {
		return deliveryItemSet;
	}

	public void setDeliveryItemSet(Set<DeliveryItem> deliveryItemSet) {
		this.deliveryItemSet = deliveryItemSet;
	}
	
	@SearchableProperty(store = Store.YES)
	@Column(precision = 15, scale = 5, nullable = true)
	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	public String getItemSn() {
		return itemSn;
	}

	public void setItemSn(String itemSn) {
		this.itemSn = itemSn;
	}

//	@ManyToOne(fetch = FetchType.LAZY)
//	public Member getMember() {
//		return member;
//	}
//
//	public void setMember(Member member) {
//		this.member = member;
//	}
	
	
	
	

}